<template>
  <div class="pt-5">
    <el-card class="box-card mx-auto py-5" style="width: 480px;">
      <el-form :model="ps" :rules="rules" status-icon ref="ruleForm" label-width="100px">
        <el-form-item label="原始密码" prop="oldPs" class="pr-4">
          <el-input v-model="ps.oldPs"></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="newPs" class="pr-4">
          <el-input v-model="ps.newPs"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="reNewPs" class="pr-4">
          <el-input v-model="ps.reNewPs"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="submitForm('ruleForm')" class="position-center mt-3" style="width: 200px;">提 交 修 改</el-button>
    </el-card>
  </div>
</template>
<script>
// import axios from 'axios'

export default {
  name: 'modifypw',
  title: '修改密码',
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value.length > 16 || value.length < 7) {
        callback(new Error('长度在 7 到 16 个字符'));
      } else if (value !== this.ps.newPs) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    return {
      ps: {
        oldPs: '',
        newPs: '',
        reNewPs: ''
      },
      rules: {
        oldPs: [
          { required: true, message: '请输入旧密码', trigger: 'blur' },
          { min: 7, max: 16, message: '长度在 7 到 16 个字符', trigger: 'blur' }
        ],
        newPs: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 7, max: 16, message: '长度在 7 到 16 个字符', trigger: 'blur' }
        ],
        reNewPs: [
          { validator: validatePass2, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.ps = {
            oldPs: '',
            newPs: '',
            reNewPs: ''
          }
          this.$refs[formName].resetFields();
          // axios.post('survey/user/updatePwd', this.ps).then(res => {
          //   console.log('11111111111111', res);
          //   if (res.data.success) {
          //     console.log('res', res);
          //     this.$message({
          //       message: '修改成功',
          //       type: 'success'
          //     });
          //     this.ps = {
          //       oldPs: '',
          //       newPs: '',
          //       reNewPs: ''
          //     }
 
          //   } else {
          //     this.$codeError(res)
          //   }
          // }).catch(error => {
          //   this.$catchError(error)
          // })
        } else {
          return false;
        }
      });
    },
  }
}
</script>
<style lang = 'scss'>
</style>